import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '@/pages/Home'

Vue.use(VueRouter)

export const createRouter = () => {
  const router = new VueRouter({
    // 同构应用中 mode 不能使用 hash
    mode: 'history', // 兼容前后端
    routes: [{
      path: '/',
      name: 'home',
      component: Home
    }, {
      path: '/about',
      name: 'about',
      // 异步路由懒加载
      component: () => import('@/pages/About')
    }, {
      path: '/posts',
      name: 'posts',
      // 异步路由懒加载
      component: () => import('@/pages/Posts')
    }, {
      path: '*',
      name: 'error404',
      component: () => import('@/pages/404')
    }]
  })

  return router
}